{include file='index/header'/}

<div style="padding:20px; ">
    <div style="background: #FFFFFF;padding: 20px 50px;">
        <div style="margin: 10px 0px;">
        <span class="layui-breadcrumb">
  <a href="">首页</a>
  <a href="">实验室预约</a>
  <a><cite>空实验室</cite></a>
</span>
        </div>
            <div class="layui-row">
                <form class="layui-form " method="get" action="">
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            <input type="text" id="test2" name="date"  placeholder="请选择时间"  class="layui-input" value="{$date}">
                        </div>
                        <div class="layui-input-inline">
                            <select name="time" lay-verify="required">
                                <option value="">请选择时间段</option>
                                {eq name="time" value="08:20-09:50"}
                                <option value="08:20-09:50" selected="selected">08:20-09:50</option>
                                {else/}
                                <option value="08:20-09:50">08:20-09:50</option>
                                {/eq}
                                {eq name="$time" value="10:10-11:40"}
                                <option value="10:10-11:40" selected="selected">10:10-11:40</option>
                                {else/}
                                <option value="10:10-11:40">10:10-11:40</option>
                                {/eq}
                                {eq name="$time" value="14:30-16:00"}
                                <option value="14:30-16:00" selected="selected">14:30-16:00</option>
                                {else/}
                                <option value="14:30-16:00">14:30-16:00</option>
                                {/eq}
                                {eq name="$time" value="16:00-17:50"}
                                <option value="16:00-17:50" selected="selected">16:00-17:50</option>
                                {else/}
                                <option value="16:00-17:50">16:00-17:50</option>
                                {/eq}
                            </select>
                        </div>
                        <button class="layui-btn" type="submit"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                    </div>

                </form>
            </div>

            <table class="layui-table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>课室名称</th>
                    <th>所在地址</th>
                    <th>承载人数</th>
                    <th>管理教师</th>
                    <th>操作</th>
                </thead>
                <tbody>
                {volist name="labs" id="lab" empty="$empty"}
                <tr>
                    <td>{$lab.id}</td>
                    <td>{$lab.name}</td>
                    <td>{$lab.address}</td>
                    <td>{$lab.people}</td>
                    <td>
                        {if $lab.teacher_id}
                        {$lab->teacher->realname|default="暂无教师信息"}
                        {else/}
                        暂无管理教师
                        {/if}
                    </td>
                    <td>
                        <a title="申请预约" onclick="lab_app(this,'{$lab.id}')" href="javascript:;">
                            <!--<i class="layui-icon">&#xe640;</i>-->
                            申请预约
                        </a>
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
        <input type="hidden" value="{$date}" id="date">
        <input type="hidden" value="{$time}" id="time">
        {if $date}
        <div class="page">
            {$labs|raw}
        </div>
        {else/}
        {/if}
    </div>
{include file='index/footer'/}
<script>
    $('#lab_app').addClass("layui-nav-itemed");
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#test2' //指定元素
        });
    });
    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    function lab_app(obj,id) {
        var ii=layer.load();
        $.post(
            "{:url('lab_app')}",
            {
                lab_id:id,
                date:$('#date').val(),
                time:$('#time').val(),
            },
            function (data) {
                if (data.statu==200){
                    layer.close(ii);
                    layer.msg(data.msg,function () {
                        window.location.href="{:url('lab/lab_app_list')}"
                    })
                } else {
                    layer.close(ii);
                    layer.msg(data.msg)
                }
            }
        )
    }
</script>

